package service

import (
	"go-project/dto/requrest"
	"go-project/models"
)

type OfficialAccountSetting struct {
	Name           string `json:"name"`
	AppID          string `json:"app_id"`
	AppSecret      string `json:"app_secret"`
	Token          string `json:"token"`
	EncodingAESKey string `json:"encoding_aes_key"`
	EncryptionType int8   `json:"encryption_type"`
}

func (officialAccountSetting *OfficialAccountSetting) Set(req *requrest.OfficialAccountSettingRequest) error {
	var systemOptions = new(models.SystemOptions)
	officialAccountSetting.Name = req.Name
	officialAccountSetting.AppID = req.AppID
	officialAccountSetting.AppSecret = req.AppSecret
	officialAccountSetting.Token = req.Token
	officialAccountSetting.EncodingAESKey = req.EncodingAESKey
	officialAccountSetting.EncryptionType = req.EncryptionType
	err := systemOptions.Set(officialAccountSetting, models.SYSTEM_OFFICIAL_ACCOUNT_NAME, models.SYSTEM_APP_GROUP)
	if err != nil {
		return err
	}
	return nil
}

func (officialAccountSetting *OfficialAccountSetting) Get() error {
	var systemOptions = new(models.SystemOptions)
	err := systemOptions.Get(officialAccountSetting, models.SYSTEM_OFFICIAL_ACCOUNT_NAME, models.SYSTEM_APP_GROUP)
	if err != nil {
		return err
	}
	return err
}
